package com.yixin.hospital.controller;

import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.dto.req.purchaseorder.GoDownCancelDrugReqDTO;
import com.yixin.hospital.entity.dto.req.purchaseorder.GoDownExchangeDrugStatusReqDTO;
import com.yixin.hospital.service.GodownCancelDrugService;
import com.yixin.hospital.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/input-godown-cancel")
@Api(value = "调库单管理", tags = "调库单管理")
public class InputGodownCancelController {

    @Resource
    private GodownCancelDrugService godownCancelDrugService;

    @GetMapping("/list2")
    @ApiOperation(value = "返库单列表")
    public ApiResult<?> list(HttpServletRequest request, @RequestParam int currentPage, @RequestParam int pageSize) {
        return godownCancelDrugService.allList(request, currentPage, pageSize);
    }

    @GetMapping("/listInfo")
    @ApiOperation(value = "返库单详情")
    public ApiResult<?> ListInfo(@RequestParam String code) {
        return godownCancelDrugService.listInfo(code);
    }

    @PostMapping("/godown-cancel-drug")
    @ApiOperation(value = "申请返库")
    @Transactional
    public ApiResult<?> goDownCancelDrug(@Valid @RequestBody GoDownCancelDrugReqDTO goDownDrugReqDTO, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return godownCancelDrugService.goDownCancelDrug(goDownDrugReqDTO, userName);
    }

    @PostMapping("/godown-cancel-drug-status")
    @ApiOperation(value = "返库")
    @Transactional
    public ApiResult<?> goDownCancelDrugStatus(@Valid @RequestBody GoDownExchangeDrugStatusReqDTO goDownExchangeDrugStatusReqDTO, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return godownCancelDrugService.goDownCancelDrugStatus(goDownExchangeDrugStatusReqDTO, userName);
    }

}
